﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using ModelCheckUtility.ModelLayer;

namespace ModelCheckUtility.ControlLayer
{
	public static class CloseCurveAreaAnalysisManger
	{
		public static List<ICloseCurveAnalays> GetResults<RoomClass, DoorClass, BoundarySegmentClass, HostInRoomClass>(Document inputDocumnet, List<Element> lstinputElement, bool ifFindDoor, List<Level> lstUseLevel, List<Phase> lstUsePhase, List<BuiltInCategory> lstUseCategory, bool ifReCalculate = false, FactoryBean<BaseAreaPacker, RoomClass, BoundarySegmentClass, DoorClass, HostInRoomClass> inputFactory = null) where RoomClass : BaseRoomPacker where DoorClass : BaseDoorPacker where BoundarySegmentClass : BaseBoundarySegmentPacker where HostInRoomClass : BaseHostInRoomPacker
		{
			if (!BaseRoomFinder<RoomClass, DoorClass, BoundarySegmentClass, HostInRoomClass>.IfUseRoomFinder || ifReCalculate)
			{
				if (inputFactory != null)
				{
					BaseRoomFinder<RoomClass, DoorClass, BoundarySegmentClass, HostInRoomClass>.GetRoomPacker(inputDocumnet, lstUseLevel, lstUsePhase, lstUseCategory, inputFactory.RoomFactory, inputFactory.DoorFactory, inputFactory.BoundarySemgentFactory, inputFactory.HostInRoomClassFactory);
				}
				else
				{
					BaseRoomFinder<RoomClass, DoorClass, BoundarySegmentClass, HostInRoomClass>.GetRoomPacker(inputDocumnet, lstUseLevel, lstUsePhase, lstUseCategory, null, null, null, null);
				}
			}
			List<ICloseCurveAnalays> list = new List<ICloseCurveAnalays>();
			BaseFamilyInstanceFinderByCurve baseFamilyInstanceFinderByCurve = new BaseFamilyInstanceFinderByCurve(inputDocumnet, BaseRoomFinder<RoomClass, DoorClass, BoundarySegmentClass, HostInRoomClass>.LstNowDoorValues);
			List<Curve> list2 = null;
			foreach (Element element in lstinputElement)
			{
				if (ifFindDoor)
				{
					list2 = Utility.GetBoundaryCurves(element);
				}
				list.Add(new BaseCloseCurvePacker(element, list2, baseFamilyInstanceFinderByCurve.FindCurveLinkBaseDoorPacker(list2)));
			}
			return list;
		}
	}
}
